<?php
	require_once("setup.inc.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
* {
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.ajaxEditLink {
	font-size:10px; 
	font-weight:bold; 
	padding-left:5px;
}
table#editInfo {
	font-size:12px;
}
-->
</style>
</head>
<body>
<h1>Test Build: Create Current Board</h1>
<div style="color:#990000; font-weight:bold ">Remember, there's always a better way!</div>
<?php
	if(!isset($_REQUEST['date'])) {
		print "<form action='" . $_SERVER['PHP_SELF'] . "'>Date (YYYYMMDD): <input type='text' name='date'><input type='submit' value='Process'></form>";
		print "</body></html>";
		exit;
	}
?>
<div style="border:thin solid #000000; padding: 10px; margin: 10px;">
<div style="font-size:16px; font-weight:bold; ">Housekeeping...</div>
<?php
	$sql = "TRUNCATE TABLE `t_current_board`";
//	$result = mysql_query($sql);
?>
<div style="border:thin solid #000066; background-color:#AAAAFF; padding: 15px; margin: 10px; font-size:12px;">SQL: <?= $sql ?></div>
</div>
<?php
	$sql = "SELECT t_sched_dates.date_id, t_sched_shifts.driver_id, t_sched_shifts.shift_id, t_sched_shifts.structure_id, t_sched_shifts.shift_start, t_sched_shifts.shift_end, t_sched_groups.point_value
			FROM t_sched_dates, t_sched_shifts, t_sched_groups, t_sched_main, t_sched_structure
			WHERE t_sched_dates.date_id = " . quote_smart($_REQUEST['date']) . "
			  AND t_sched_dates.table_id = t_sched_main.table_id
			  AND t_sched_main.table_id = t_sched_structure.table_id
			  AND t_sched_structure.structure_id = t_sched_shifts.structure_id
			  AND t_sched_main.group_id = t_sched_groups.group_id";
	$result = mysql_query($sql);
?>
<div style="border:thin solid #000000; padding: 10px; margin: 10px;">
<div style="font-size:16px; font-weight:bold; ">Insert All Shifts from Shift Table</div>
<div style="border:thin solid #000066; background-color:#AAAAFF; padding: 15px; margin: 10px; font-size:12px;">SQL: <?= $sql ?></div>
<div style="font-size:12px; font-weight:bold; ">Rows: <?= mysql_num_rows($result) ?></div>
<div style="font-size:10px; ">
<?php
	while($row = mysql_fetch_assoc($result)) {
		$insert_sql = "INSERT INTO t_current_board (date_id,driver_id,shift_id,structure_id,shift_start,shift_end,point_weight) VALUES (" . $row['date_id'] . ", " . $row['driver_id'] . ", " . $row['shift_id'] . ", " . $row['structure_id'] . ", " . $row['shift_start'] . ", " . $row['shift_end'] . ", " . $row['point_value'] . ")";
		$insert_result = mysql_query($insert_sql);
		if(mysql_affected_rows() == 1) {
			$color = 'green';
		} else {
			$color = 'red';
			$error = 'MySQL said: ' . mysql_errno() . ' - ' . mysql_error();
			print "<span style='font-weight: bold; color: red;'>" . $error . "</span><br />\n";
		}
		print "INSERT: <span style='color: " . $color . ";'>" . $insert_sql . "</span><br />\n";
	}
?></div>
</div>

<?php
	$sql = "SELECT *
			FROM t_workswap
			WHERE shift_date = 20070215";
	$result = mysql_query($sql);
?>
<div style="border:thin solid #000000; padding: 10px; margin: 10px;">
<div style="font-size:16px; font-weight:bold; ">Update Workswapped Shifts</div>
<div style="border:thin solid #000066; background-color:#AAAAFF; padding: 15px; margin: 10px; font-size:12px;">SQL: <?= $sql ?></div>
<div style="font-size:12px; font-weight:bold; ">Rows: <?= mysql_num_rows($result) ?></div>
<div style="font-size:10px; ">
<?php
	while($row = mysql_fetch_assoc($result)) {
		print_r($row);
		//$insert_sql = "INSERT INTO t_current_board (date_id,driver_id,shift_id,structure_id,shift_start,shift_end,point_weight) VALUES (" . $row['date_id'] . ", " . $row['driver_id'] . ", " . $row['shift_id'] . ", " . $row['structure_id'] . ", " . $row['shift_start'] . ", " . $row['shift_end'] . ", " . $row['point_value'] . ")";
		//$insert_result = mysql_query($insert_sql);
		//if(mysql_affected_rows() == 1) {
		//	$color = 'green';
		//} else {
		//	$color = 'red';
		//	$error = 'MySQL said: ' . mysql_errno() . ' - ' . mysql_error();
		//	print "<span style='font-weight: bold; color: red;'>" . $error . "</span><br />\n";
		//}
		print "INSERT: <span style='color: " . $color . ";'>" . $insert_sql . "</span><br />\n";
	}
?></div>
</div>

</body>
</html>
